package com.example.demo.controller;

import com.example.demo.model.ResposeModel;
import com.example.demo.service.SchoolService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/*驾校*/
@Controller
@RequestMapping("/api/School")
public class SchoolController {
	private Logger log = LoggerFactory.getLogger(SchoolController.class);
	@Autowired
	private SchoolService schoolService;

	@RequestMapping("/selectSchools/cityId/{cityId}/districtId/{districtId}/minprice/{minprice}/maxprice/{maxprice}/drivingModelId/{drivingModelId}/pageIndex/{pageIndex}/pageSize/{pageSize}")
	@ResponseBody
	public ResposeModel selectSchools(@PathVariable("cityId") Integer cityId,
			@PathVariable("districtId") Integer districtId, @PathVariable("minprice") Double minprice,
			@PathVariable("maxprice") Double maxprice, @PathVariable("drivingModelId") Integer drivingModelId,
			@PathVariable("pageIndex") Integer pageIndex, @PathVariable("pageSize") Integer pageSize) {
		ResposeModel res = new ResposeModel();
		try {
			res.setData(schoolService.selectSchools(cityId, districtId, minprice, maxprice, drivingModelId, pageIndex,
					pageSize));
		} catch (Exception e) {
			res.setStatus("0");
			res.setMsg("获取数据出错");
		}

		return res;
	}

	@RequestMapping("/selectSchool/id/{id}")
	@ResponseBody
	public ResposeModel selectSchool(@PathVariable("id") Integer id) {
		ResposeModel res = new ResposeModel();
		try {
			res.setData(schoolService.selectSchool(id));
		} catch (Exception e) {
			res.setStatus("0");
			res.setMsg("获取数据出错");
		}

		return res;
	}

	@RequestMapping("/getSchoolClassesAtOnceBySchool/schoolId/{schoolId}/pageIndex/{pageIndex}/pageSize/{pageSize}")
	@ResponseBody
	public ResposeModel getSchoolClassesAtOnceBySchool(@PathVariable("schoolId") Integer schoolId
			,@PathVariable("pageIndex") Integer pageIndex
			,@PathVariable("pageSize") Integer pageSize) {
		ResposeModel res = new ResposeModel();
		try {
			res.setData(schoolService.getSchoolClassesAtOnceBySchool(schoolId,pageIndex,pageSize));
		} catch (Exception e) {
			res.setStatus("0");
			res.setMsg("获取数据出错");
		}

		return res;
	}

	
	
	
}
